
function queryIp(that) {
    var ip = that.attr('data-ip');
    var url = that.attr('data-url');
    layer.confirm('确定要查询IP【'+ip+'】归属地吗？', {title:'请确认'},function (index) {
        layer.close(index);
        $(that).prev('.layui-icon-loading').show();
        $(that).text('查询中');
        setTimeout(function (){
            $.ajax({
                type: 'GET',
                url: url,
                data: {ip: ip},
                dataType: "json",
                success: function (data) {
                    $(that).prev('.layui-icon-loading').hide();
                    if (data.code == 1) {
                        notify.success(data.msg);
                        $(that).text(data.result);
                        $(that).attr('onclick','');
                    }else{
                        notify.error(data.msg);
                    }
                }
            });
        },500)
    });
}



let openDrawer = function (title, url, w, offset, h = '') {
    var anim, height = h ? h : '100%'
    switch (offset) {
        case "r":
            anim = 'slideLeft';
            break;
        case "l":
            anim = 'slideRight';
            break;
        case "b":
            anim = 'slideUp';
            break;
        case "t":
            anim = 'slideDown';
            break;
    }
    layui.layer.open({
        type: 2,
        offset: offset,
        anim: anim, // 从右往左
        area: [w, height],
        shade: 0.3,
        shadeClose: true,
        id: 'ID-demo-layui.layer-direction-r',
        title: [title, 'font-size:14px;color:#000;text-align: left;font-weight: bold'],
        content: url,
        success: function () {
            $('.layui-layui.layer-setwin').find('.layui-icon').removeClass('layui-icon-close').addClass('layui-icon-error')
        }
    });
}

function layerLoad(text = '加载中....') {
    layui.layer.msg('<div><i class="layui-icon layui-icon-loading-1 layui-anim layui-anim-rotate layui-anim-loop"></i> ' + text + '', {
        shade: 0.8,
        time: 99999
    });
}


/** 菜单树全局展开与折叠 */
function openAllCate(that) {
    var text = $('.show_text').text();
    if (text == '展开') {
        $(".showAll").show();
        $('.show_text').text('折叠');
        $('.x-show').attr('status', 'false').html('&#xe625;');
    } else {
        $(".showAll").hide();
        $('.show_text').text('展开');
        $('.x-show').attr('status', 'true').html('&#xe623;');

    }
}
/** 公共弹出层 */
function zhiju_show(title, url, w, h, full = 0) {
    if (title == null || title == '') title = false;
    if (url == null || url == '') url = "404.html";
    if (w == null || w == '' || $(window).width() < w) w = ($(window).width() * 0.9);
    if (h == null || h == '' || $(window).height() < h) h = ($(window).height() - 50);
    if (full == '1') {
        let index = layui.layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            anim: 2,
            title: title,
            content: url,

        });
        layui.layui.layer.full(index);
    } else {
        layui.layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            anim: 2,
            title: title,
            content: url
        });
    }
}


/** 公共删除 */
function destroys(obj, url, id, key, val) {
    layui.layer.confirm('确认要删除吗？', function (index) {
        layui.layer.load(2);
        $.post(url, {id: id, key: key, val: val}, function (data) {
            layui.layer.closeAll();
            if (data.code == 1) {
                $(obj).parents("tr").remove();
                notify.success(data.msg);
            } else {
                notify.error(data.msg);
            }
        });
    });
}

